/**  
 * @Title: PackGoodsController.java
 * @Package com.silverbox.sweeporder.controller.shopcart
 * @author litao
 * @date 2018年1月4日
 */
package com.silverbox.sweeporder.controller.shopcart;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.silverbox.core.result.CoreResponse;
import com.silverbox.core.result.CoreResponse.StatusInfo;
import com.silverbox.core.util.StringUtils;
import com.silverbox.sweeporder.controller.shopcart.entryvo.AllPackEntryVO;
import com.silverbox.sweeporder.controller.shopcart.entryvo.SinglePackEntryVO;
import com.silverbox.sweeporder.service.shopcart.ShopCartService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * ClassName: PackGoodsController 
 * @author litao
 * @date 2018年1月4日
 */
@Controller
@RequestMapping("packGoods")
@Api(tags={"打包接口"})
public class PackGoodsController {
	
	@Autowired
	private ShopCartService shopCartService;
	
	@RequestMapping(value = "singlePackGoods", method = RequestMethod.PUT)
	@ResponseBody
	@ApiOperation(value = "单个商品打包（可调用）")
	public CoreResponse<Map<String,Object>> getSinglePackGoods(HttpSession session,
			@RequestBody(required=true) SinglePackEntryVO singlePackEntry ) {
		
		CoreResponse<Map<String,Object>> res = new CoreResponse<Map<String,Object>>();
		if (singlePackEntry==null || StringUtils.isEmpty(singlePackEntry.getBuyerId()) || singlePackEntry.getGoodsCartId() == null
				|| singlePackEntry.getPackCount() == null || singlePackEntry.getStoreId() == null) {
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}
		
		res = shopCartService.updateSinglePackGoods(singlePackEntry);
		
		return res;
	}
	
	@RequestMapping(value = "allPackGoods", method = RequestMethod.PUT)
	@ResponseBody
	@ApiOperation(value = "整单打包商品（可调用）")
	public CoreResponse<Map<String, Integer>> getAllPackGoods(HttpSession session,
			@RequestBody(required=true) AllPackEntryVO allPackEntry) {
		
		CoreResponse<Map<String, Integer>> res = new CoreResponse<Map<String, Integer>>();
		if (allPackEntry == null || StringUtils.isEmpty(allPackEntry.getBuyerId())
				|| allPackEntry.getStoreId() == null) {
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}
		
		res = shopCartService.updateAllPackGoods(allPackEntry);
		return res;
	}
	
	@RequestMapping(value = "removeSinglePackGoods", method = RequestMethod.PUT)
	@ResponseBody
	@ApiOperation(value = "取消单个打包商品（可调用）")
	public CoreResponse<Map<String, Integer>> removeSinglePackGoods(HttpSession session,
			@RequestBody(required = true) Map<String,Integer> goodsCartId) {
		CoreResponse<Map<String,Integer>> res = new CoreResponse<Map<String,Integer>>();
		if(goodsCartId==null || goodsCartId.get("goodsCartId")==null){
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}
		res = shopCartService.updateRemoveSinglePackGoods(goodsCartId.get("goodsCartId"));
		return res;
	}
}
